//封装获取坐标的函数
import { ref, onMounted, onUnmounted } from 'vue';
// hook文件的命名规则 usexxx名字
export default function useGetMousePosition() {
    const x = ref(0);
    const y = ref(0);

    const updatePosition = (e: MouseEvent) => {
        x.value = e.pageX;
        y.value = e.pageY;
    };
    onMounted(() => {
        document.addEventListener("click", updatePosition);
    });

    onUnmounted(() => {
        document.removeEventListener("click", updatePosition);
    });
    return {
        x, y
    }
}